package com.zzyl.serve.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.zzyl.common.core.domain.R;
import com.zzyl.serve.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.serve.domain.NursingProject;
import com.zzyl.serve.service.INursingProjectService;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.common.core.page.TableDataInfo;

/**
 * 护理项目Controller
 *
 * @author wangyc
 * @date 2025-08-11
 */

@RestController
@RequestMapping("/nursing/project")
@Api(tags = "护理项目管理", description = "护理项目相关接口")
public class NursingProjectController extends BaseController
{
    @Autowired
    private INursingProjectService nursingProjectService;




    @PreAuthorize("@ss.hasPermi('nursing:project:list')")
    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public R<List<NursingProjectVo>> queryAll() {
        List<NursingProjectVo> list = nursingProjectService.queryAll();
        return R.ok(list);
    }

    /**
     * 查询护理项目列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:project:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询护理项目列表", notes = "根据条件查询护理项目列表")
    @ApiResponses({
        @ApiResponse(code = 200, message = "操作成功"),
        @ApiResponse(code = 401, message = "未授权"),
        @ApiResponse(code = 500, message = "服务器内部错误")
    })
    public TableDataInfo<NursingProject> list(@ApiParam(value = "护理项目查询参数", required = false) NursingProject nursingProject)
    {
        startPage();
        List<NursingProject> list = nursingProjectService.selectNursingProjectList(nursingProject);
        return getDataTable(list);
    }

    /**
     * 导出护理项目列表
     */
    @ApiOperation(value = "导出护理项目列表", notes = "将护理项目数据导出为Excel文件")
    @PreAuthorize("@ss.hasPermi('nursing:project:export')")
    @Log(title = "护理项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiResponses({
        @ApiResponse(code = 200, message = "导出成功"),
        @ApiResponse(code = 401, message = "未授权"),
        @ApiResponse(code = 500, message = "服务器内部错误")
    })
    public void export(HttpServletResponse response, @ApiParam(value = "护理项目查询参数", required = false) NursingProject nursingProject)
    {
        List<NursingProject> list = nursingProjectService.selectNursingProjectList(nursingProject);
        ExcelUtil<NursingProject> util = new ExcelUtil<NursingProject>(NursingProject.class);
        util.exportExcel(response, list, "护理项目数据");
    }

    /**
     * 获取护理项目详细信息
     */
    @ApiOperation(value = "获取护理项目详细信息", notes = "根据ID获取护理项目的详细信息")
    @PreAuthorize("@ss.hasPermi('nursing:project:query')")
    @GetMapping(value = "/{id}")
    @ApiResponses({
        @ApiResponse(code = 200, message = "操作成功"),
        @ApiResponse(code = 400, message = "参数无效"),
        @ApiResponse(code = 401, message = "未授权"),
        @ApiResponse(code = 404, message = "护理项目未找到"),
        @ApiResponse(code = 500, message = "服务器内部错误")
    })
    public R<NursingProject> getInfo(@ApiParam(value = "护理项目ID", required = true) @PathVariable("id") Long id)
    {
        return R.ok(nursingProjectService.selectNursingProjectById(id));
    }

    /**
     * 新增护理项目
     */
    @PreAuthorize("@ss.hasPermi('nursing:project:add')")
    @Log(title = "护理项目", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增护理项目", notes = "创建一个新的护理项目")
    @ApiResponses({
        @ApiResponse(code = 200, message = "操作成功"),
        @ApiResponse(code = 400, message = "参数无效"),
        @ApiResponse(code = 401, message = "未授权"),
        @ApiResponse(code = 500, message = "服务器内部错误")
    })
    public AjaxResult add(@ApiParam(value = "护理项目信息", required = true) @RequestBody NursingProject nursingProject)
    {
        return toAjax(nursingProjectService.insertNursingProject(nursingProject));
    }

    /**
     * 修改护理项目
     */
    @PreAuthorize("@ss.hasPermi('nursing:project:edit')")
    @Log(title = "护理项目", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改护理项目", notes = "更新已存在的护理项目信息")
    @ApiResponses({
        @ApiResponse(code = 200, message = "操作成功"),
        @ApiResponse(code = 400, message = "参数无效"),
        @ApiResponse(code = 401, message = "未授权"),
        @ApiResponse(code = 404, message = "护理项目未找到"),
        @ApiResponse(code = 500, message = "服务器内部错误")
    })
    public AjaxResult edit(@ApiParam(value = "护理项目信息", required = true) @RequestBody NursingProject nursingProject)
    {
        return toAjax(nursingProjectService.updateNursingProject(nursingProject));
    }

    /**
     * 删除护理项目
     */
    @PreAuthorize("@ss.hasPermi('nursing:project:remove')")
    @Log(title = "护理项目", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除护理项目", notes = "根据ID批量删除护理项目")
    @ApiResponses({
        @ApiResponse(code = 200, message = "操作成功"),
        @ApiResponse(code = 400, message = "参数无效"),
        @ApiResponse(code = 401, message = "未授权"),
        @ApiResponse(code = 404, message = "护理项目未找到"),
        @ApiResponse(code = 500, message = "服务器内部错误")
    })
    public AjaxResult remove(@ApiParam(value = "护理项目ID数组", required = true) @PathVariable Long[] ids)
    {
        return toAjax(nursingProjectService.deleteNursingProjectByIds(ids));
    }
}
